package com.my.hotel.mapper;

import com.my.hotel.entity.KfRoom;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface KfRoomMapper {

    //查询
    @Select("select * from tb_kf_room")
    public List<KfRoom> getList();

    //新增
    @Insert("insert into tb_kf_room values(null,#{kfArea},#{kfDesc},#{kfPrice},#{kfHdPrice},#{kfTypeId},#{hdId})")
    @Options(useGeneratedKeys=true,keyProperty = "id")
    public void addKfRoom(KfRoom kfRoom);

    //根据id查询对象信息
    @Select("select * from tb_kf_room where id =#{id}")
    public KfRoom getKfRoomById(int id);

    //修改
    @Update("update tb_kf_room set kf_area=#{kfArea},kf_desc=#{kfDesc},kf_price=#{kfPrice},kf_hd_price=#{kfHdPrice}," +
            "kf_type_id=#{kfTypeId},hd_id=#{hdId} where id=#{id}")
    public void updateKfRoom(KfRoom kfRoom);

    //删除
    @Delete("delete from tb_kf_room where id =#{id}")
    public void deleteKfRoom(int id);

    //查询客房type对应房间的平均价格
    @Select("select t.type_name name,AVG(r.kf_price) price from tb_kf_room r , tb_kf_type t " +
            "where r.kf_type_id =t.id group by t.type_name")
    public List<Map> getAvg();
}
